package com.nl.controller.web.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.nl.controller.common.model.Response;
import com.nl.controller.common.util.ResponseUtil;
import com.nl.controller.web.bean.JzzwCheck;
import com.nl.controller.web.service.JzzwCheckService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
@RequestMapping("/jzzwCheck")
public class JzzwCheckController {
	
 @Autowired
 private JzzwCheckService jzzwCheckService;
 
 @ApiOperation(value = "精准政务审核", notes = "分页查询精准政务审核信息")
 @ApiImplicitParams({
         @ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "String"),
         @ApiImplicitParam(name = "limit", value = "每页数量", required = true, dataType = "String"),
         @ApiImplicitParam(name = "cityId", value = "城市编号", required = true, dataType = "String"),
         @ApiImplicitParam(name = "mgrId", value = "项目编号", required = true, dataType = "String"),
         @ApiImplicitParam(name = "mgrName", value = "项目名称", required = true, dataType = "String"),
         @ApiImplicitParam(name = "checkResult", value = "审核结果", required = true, dataType = "String")
 })
 @PostMapping("find")
 public Response findJzzwCheck(
         @RequestParam(value = "page", required = true) int page,
         @RequestParam(value = "limit", required = true) int limit,
         @RequestParam(value = "cityId", required = false) String cityId,
         @RequestParam(value = "mgrId", required = false) String mgrId,
         @RequestParam(value = "mgrName", required = false) String mgrName,
         @RequestParam(value = "checkResult", required = false) String checkResult,
         @RequestParam Map<String, Object> paramMap
 ) {
   /*  if (("".equals(mgrId) || mgrId == null)&&("".equals(cityId) || cityId == null)
    	 && ("".equals(mgrName) || mgrName == null)&& ("".equals(checkResult) || checkResult == null)) {
         throw new SmsException("请选择查询条件，开始查询");
     } else {*/
         PageInfo<JzzwCheck> pageInfo = jzzwCheckService.findJzzwCheck(page, limit, cityId, mgrId, mgrName, checkResult);
         log.info(" 查询模板信息：{}", paramMap.toString());
         log.debug("查询模板信息返回参数：{}", pageInfo.getList().toString());
         return ResponseUtil.sucess(pageInfo.getList(), pageInfo.getTotal());
     /*}*/
 }
	
 @ApiOperation(value = "精准政务审核", notes = "根据城市查询项目名称")
 @ApiImplicitParam(name = "cityId", value = "城市编号", required = true, dataType = "String")
 @PostMapping("findByCityId")
 public Response<JzzwCheck> findOperatorByCityId(
         @RequestParam(value = "cityId") String cityId
 ) {
     log.info("根据城市查询项目信息参数：{}", cityId);
     List<JzzwCheck> list = new ArrayList<>();
     if (cityId != null && !"undefined".equals(cityId) && cityId != "") {
     	 list = jzzwCheckService.findMgrByCityId(cityId);
     }
     log.debug("根据城市查询项目信息返回数据：{}", list.size());
     return ResponseUtil.sucess(list);
 }
 
 @ApiOperation(value = "精准政务审核", notes = "项目名称联想")
 @PostMapping("selectMgrNameLike")
 public Response<String> selectMgrNameLike(@RequestParam(value = "key", required = true) String key,
         @RequestParam(value = "cityId", required = false) String cityId
 		) {
     
     log.info("项目名称联想参数：{}", key);
     List<JzzwCheck> list = new ArrayList<>();
     if (key != null && !"undefined".equals(key) && key != "") {
         list = jzzwCheckService.selectMgrNameLike(key,cityId);
     }
     log.debug("项目名称联想返回数据：{}", list.size());
     return ResponseUtil.sucess(list);
 }  
 
 @ApiOperation(value = "精准政务审核查看", notes = "通过项目id查询精准政务审核查看")
 @PostMapping("findJzzwCheckByMgrId")
 public Response findJzzwCheckByMgrId(
         @RequestParam(value = "mgrId", required = false) String mgrId) {
	 JzzwCheck jzzwCheck;
	 jzzwCheck = jzzwCheckService.findJzzwCheckByMgrId(mgrId);
     log.info(" 项目信息：{}", jzzwCheck.toString());
     return ResponseUtil.sucess(jzzwCheck);
 }
 
 @ApiOperation(value = "精准政务模板审核", notes = "精准政务模板审核")
 @ApiImplicitParams({
         @ApiImplicitParam(name = "mgrId", value = "项目编号", required = true, dataType = "String"),
         @ApiImplicitParam(name = "checkResult", value = "审核结果", required = true, dataType = "String"),
         @ApiImplicitParam(name = "checkMsg", value = "审核内容", required = false, dataType = "String"),
 })
 @PostMapping("checkEnd")
 public Response checkTemlplate(
         @RequestParam(value = "mgrId", required = true) String mgrId,
         @RequestParam(value = "checkResult", required = true) String checkResult,
         @RequestParam(value = "checkMsg", required = true) String checkMsg,
         @RequestParam Map<String, Object> paramMap
 ) {
     int result;
     log.info("精准政务模板审核参数:{}" + paramMap.toString());
     result = jzzwCheckService.templateCheck(mgrId, checkResult, checkMsg);
     if (1 == result) {                   
         return ResponseUtil.sucess("审核成功");
     } else {
         return ResponseUtil.sucess("审核失败请重试");
     }
 }
}
